package com.tdr.myandroid.control;

import com.tdr.myandroid.model.EventObject;
import com.tdr.myandroid.model.EventsManger;

import java.util.ArrayList;

/**
 * Created by Administrator on 2014/7/17.
 */
public class WorkerThread extends Thread {
    @Override
    public void run() {
        super.run();
        while (true) {
            try {
                dispatchWork();
                Thread.sleep(1000);
            }
            catch (InterruptedException e) {
                break;
            } finally {

            }
        }
    }

    public void dispatchWork() {
        ArrayList<EventObject> events = EventsManger.getMgr().getEvents();

        if (EventsManger.getMgr().hasReachedCondition()) {
            for (EventObject singleEvent : events) {
                if (singleEvent.isActive()) {
                    continue;
                }
                if (EventsManger.getMgr().matchEvent(singleEvent)) {
                    singleEvent.startWork();
                }
            }
        }
    }
}
